package com.lswms.common.utils;

import org.apache.commons.lang3.StringUtils;

public class LocaUtils {
	
	/**
	 * 货位
	 * 项道，从上到下，1项道，2项道
	 * 排，从上到下，1--6排
	 * 列，从左到右，0-80排
	 */
	public static String formatNum(int a) {
		return String.format("%03d", a);
	}
	/**
	 * 获取货位排
	 * @param args
	 */
	public static int getr(String locNo){
		return Integer.parseInt(locNo.substring(0, 3));
	}
	/**
	 * 1，4里层
	 * @param a
	 * @return
	 */
	public static int getSeat(int a){
		int set = 1;
		if(a == 1 || a == 4) {
			set = 2;
		}
		return set;
	}

	/**
	 * 获取货位列
	 * @param args
	 */
	public static int getc(String locNo){
		return Integer.parseInt(locNo.substring(3, 6));
	}
	/**
	 * 获取货位层
	 * @param args
	 */
	public static int getl(String locNo){
		return Integer.parseInt(locNo.substring(6, 9));
	}
	/**
	 * 项道
	 * @param a
	 * @return
	 */
	public static int getLane(int a) {
		int x = 1;
		if(a <= 4) {
			x = 1;
		}else {
			x = 2;
		}
		return x;
	}
	/**
	 * 出库目的地--从货位到目的地
	 */
	public static String toLocate(String locateNo,String agvTo) {
		int row = LocaUtils.getr(locateNo);
		if(StringUtils.isBlank(agvTo) && row <= 4) {
			return "003000001";
		}else if(StringUtils.isBlank(agvTo) && row > 4) {
			return "005000001";
		}else if(StringUtils.isNotBlank(agvTo) && row <= 4) {
			return "002080001";
		}else if(StringUtils.isNotBlank(agvTo) && row > 4) {
			return "006080001";
		}
		return null;
	}
	/**
	 * 入库--从目的地到货位
	 * @param locateNo
	 * @param agvTo
	 * @return
	 */
	public static String fromLocate(String locateNo,String agvTo) {
		int row = LocaUtils.getr(locateNo);
		if("1101".equals(agvTo)) {
			return "002000001";
		}else if("1201".equals(agvTo)) {
			return "003000001";
		}else if("1301".equals(agvTo)) {
			return "005000001";
		}else if("1401".equals(agvTo)) {
			return "006000001";
		}else if(row <= 4) {
			return "003080001";
		}else if(row > 4){
			return "005080001";
		}
		return null;
	}
	/**
	 * 回库获取agv_to
	 * @param locateNo
	 * @return
	 */
	public static String backLocate(String locateNo) {
		int row = LocaUtils.getr(locateNo);
		if(row <= 4) {
			return "1201";
		}else {
			return "1301";
		}
	}

	/**
	 * 获取货位对应的外货位
	 * @param args
	 */
	public static String getout(String locNo){
		int r = getr(locNo);
		int c = getc(locNo);
		int l = getl(locNo);
		if(r == 1) {
			return formatNum(2)+""+formatNum(c)+""+formatNum(l);
		}else if(r == 4) {
			return formatNum(3)+""+formatNum(c)+""+formatNum(l);
		}
		return "";
	}



	public static void main(String[] args) {

		//行
		int row = 6;
		//列
		int col = 40;
		//层
		int level = 6;
		
		for(int a = 1;a <= row;a++) {
			for(int b = 0;b <= col;b++) {
				for(int c = 1;c <= level;c++) {
					//项道
					int x = 1;
					if(a <= 4) {
						x = 1;
					}else {
						x = 2;
					}
					//System.out.println(formatNum(a)+"    "+formatNum(b)+"    "+formatNum(c));
					String locNo = formatNum(a)+""+formatNum(b)+""+formatNum(c);
					//System.out.println(locNo);
				}
			}
		}
		
		System.out.println(getout("001000002"));
		
	}

}
